package com.dianhun.es.other;

import org.junit.jupiter.api.Test;

/**
 * @author cyt
 * @create 2020-08-28 下午 5:08
 */
public class sort {

    public static void main(String[] args) {

    }

    /**
     * @param array string字符串一维数组
     * @return string字符串一维数组
     */

    @Test
    public void quick_sort() {
        // write code here
        String[] strings = new String[]{"nice", "try", "do"};
        sort(strings, 0, strings.length);
        for (String string : strings) {

            System.out.println(string);
        }
       // return strings;
    }

    public void sort(String[] array, int l, int r) {

        int i, j;
        String first, temp;
        i = l;
        j = r;
        first = array[l];
        while (true) {
            while ((++i < r - 1) && array[i].compareTo(first) < 0) ;
            while ((--j > l) && array[j].compareTo(first) > 0) ;

            if (i >= j) {
                break;
            }

            temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
        array[l] = array[j];
        array[j] = first;
        if (l < j) {
            sort(array, l, j);
        }
        if (r > i) {
            sort(array, i, r);
        }

    }
}
